//  ReceivedListMapViewController.m
//  Roskildeapp
//
//  Created by My Name on 11/21/11.
//  Copyright 2011 __MyCompanyName__. All rights reserved.
//

#import "ReceivedListMapViewController.h"
#import "MapViewAnnotation.h"


@implementation ReceivedListMapViewController
@synthesize managedObjectContext,fetchedResultsController,dateFormatter;
@synthesize mapView;

- (id)initWithManagedObjectContext:(NSManagedObjectContext*)objectContext
{
    self = [super init];
    if (self) {
        self.managedObjectContext = objectContext;
        self.title = @"Received Locations";
        
        UIImage *tabImage = [[UIImage imageNamed:@"tabIconReceived.png"] autorelease];
        self.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"Received Locations" image:tabImage tag:1];
    }
    return self;
}

- (void)didReceiveMemoryWarning
{
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];
    
    // Release any cached data, images, etc that aren't in use.
}

#pragma mark - View lifecycle

/*
 // Implement loadView to create a view hierarchy programmatically, without using a nib.
 - (void)loadView
 {
 }
 */


// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad
{
    NSLog(@"Vi nåede ind i til locations!");
    // Set some coordinates for our position (Buckingham Palace!)
	CLLocationCoordinate2D location;
    CLLocationCoordinate2D location2;
    CLLocationCoordinate2D location3;
    location3.latitude = (double) 52.1012;
    location3.longitude = (double) -1.122435;
    location2.latitude = (double) 50.002012;
    location2.longitude = (double) -0.152435;
	location.latitude = (double) 51.501468;
	location.longitude = (double) -0.141596;
	
	// Add the annotation to our map view
	MapViewAnnotation *newAnnotation = [[MapViewAnnotation alloc] initWithTitle:@"Buckingham Palace" andCoordinate:location subtitle:@"Winwin"];
    [self.mapView addAnnotation:newAnnotation];
	[newAnnotation release];
    MapViewAnnotation *newAnnotation2 = [[MapViewAnnotation alloc] initWithTitle:@"Random place" andCoordinate:location2 subtitle:@"Winwin"];
	[self.mapView addAnnotation:newAnnotation2];
	[newAnnotation2 release];
    MapViewAnnotation *newAnnotation3 = [[MapViewAnnotation alloc] initWithTitle:@"Vildere sted!" andCoordinate:location3 subtitle:@"Winwin"];
    [self.mapView addAnnotation:newAnnotation3];
    [newAnnotation3 release];
}

// When a map annotation point is added, zoom to it (15000 range)
- (void)mapView:(MKMapView *)mv didAddAnnotationViews:(NSArray *)views
{
	MKAnnotationView *annotationView = [views objectAtIndex:0];
	id <MKAnnotation> mp = [annotationView annotation];
	MKCoordinateRegion region = MKCoordinateRegionMakeWithDistance([mp coordinate], 150000, 150000);
	[mv setRegion:region animated:YES];
	[mv selectAnnotation:mp animated:YES];
}


- (void)viewDidUnload
{
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    // Return YES for supported orientations
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

@end
